import React, { Component } from 'react'

export default class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      message: "hello world",
    }
  }
  render() {
    return (
      <div>
        <h2>当前计数：{this.state.message}</h2>
        <button onClick={e => this.chengeText()}>改变文本</button>
      </div>
    )
  }
  chengeText() {
    // setState是异步更新
    // this.setState(更新的state,回调函数)

    // 方式1：获取异步更新的state
    this.setState({
      message: "你好"
    }, () => {
      // console.log(this.state.message);
    })
  }
  componentDidUpdate() {
    // 方式2：获取异步更新的state
    console.log(this.state.message);
  }
}
